package com.snapan.controller;

import com.snapan.common.Result;
import com.snapan.entity.FileHistory;
import com.snapan.es.service.EsSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/api/search")
@RestController
public class SearchController {

    @Autowired
    private EsSearchService esSearchService;



    @PostMapping("/advanced")
    public List<Map<String,Object>> advancedSearch(@RequestBody FileHistory history) {
        System.out.println(history);
        List<Map<String, Object>> results =esSearchService.multiConditionSearch(history.getUserId(), history);

        return results;
    }

    @PostMapping("/match")
    public Result<List<Map<String, Object>>> getMatchContent(@RequestBody FileHistory history) {
        // 调用服务层，查询实时匹配结果（仅返回文件名和内容，限制10条）
        List<Map<String, Object>> matchList = esSearchService.getMatchContent(history.getUserId(),history);
        return Result.success(matchList);
    }

    @PostMapping("/advancedRecycled")
    public List<Map<String,Object>> advancedSearchRecycled(@RequestBody FileHistory history) {
        System.out.println(history);
        List<Map<String, Object>> results =esSearchService.multiConditionRecycleSearch(history.getUserId(), history);

        return results;
    }

    @PostMapping("/matchRecycled")
    public Result<List<Map<String, Object>>> getMatchContentRecycled(@RequestBody FileHistory history) {
        // 调用服务层，查询实时匹配结果（仅返回文件名和内容，限制10条）
        List<Map<String, Object>> matchList = esSearchService.getMatchContentRecycled(history.getUserId(),history);
        return Result.success(matchList);
    }

    @PostMapping("/advancedShare")
    public List<Map<String,Object>> advancedSearchShare(@RequestBody FileHistory history) {
        System.out.println(history);
        List<Map<String, Object>> results =esSearchService.multiConditionShareSearch(history.getUserId(), history);

        return results;
    }

    @PostMapping("/matchShare")
    public Result<List<Map<String, Object>>> getMatchContentShare(@RequestBody FileHistory history) {
        // 调用服务层，查询实时匹配结果（仅返回文件名和内容，限制10条）
        System.out.println(history);
        List<Map<String, Object>> matchList = esSearchService.getMatchContentShare(history.getUserId(),history);
        return Result.success(matchList);
    }

}
